package com.dao;

import java.util.List;

import org.hibernate.Session;

import com.db.factory.DBSessionFactory;
import com.mod.Product;
import com.mod.User;

public class Dao {
	public boolean Dl(String name,String pwd){
		Session session = DBSessionFactory.getSession();
		session.beginTransaction();
		User user = (User) session.createQuery("from User where name=:n and pwd=:m").setString("n",name).setString("m",pwd).uniqueResult();
		session.getTransaction().commit();
		DBSessionFactory.closeSession(session);
		if(user==null){
			return false;
		}
		return true;
		
		
		
		
	}
	public boolean zhuce(String name,String password){
		Session session = DBSessionFactory.getSession();
		User user = new User(name,password);
		session.beginTransaction();
		session.save(user);
		session.getTransaction().commit();
		DBSessionFactory.closeSession(session);
		return true;
		
	}
	public List<Product> show(){
		Session session = DBSessionFactory.getSession();
		session.beginTransaction();
		List<Product> list = session.createQuery("from Product").list();
		session.getTransaction().commit();
		DBSessionFactory.closeSession(session);
	    return list;
	}
	public Product car(int pid){
		Session session = DBSessionFactory.getSession();
		session.beginTransaction();
		Product product = (Product) session.get(Product.class,pid);
		session.getTransaction().commit();
		DBSessionFactory.closeSession(session);
	    return product;
	}
	public void save(Object o){
		Session session = DBSessionFactory.getSession();
		session.beginTransaction();
		session.save(o);	
		session.getTransaction().commit();
		DBSessionFactory.closeSession(session);
	  
	}

}
